package com.company;

import java.sql.*;

public class LIGANDS {
    private static String driver = "oracle.jdbc.driver.OracleDriver";
    private static String url = "jdbc:oracle:thin:@localhost:1521:XE";
    private static String user="hr";
    private static String password="123456";

    public static void main(String[] args){
        Connection conn=null;
        try {
            Class.forName(driver);//用来加载程序
            conn= DriverManager.getConnection(url,user,password);//连接数据库
            String sql="select * from DORMITORY";
            PreparedStatement pst=conn.prepareStatement(sql);//准备执行SQL语句
            ResultSet rs= pst.executeQuery();
            while(rs.next())//判断有没有下一行
                 {
                     int d_id=rs.getInt(1);
                     String ssn=rs.getString(2);
                     String dfl=rs.getString(3);
                     String dst=rs.getString(4);
                     int dlive=rs.getInt(5);
                     String dsp=rs.getString(6);
                     String dcl=rs.getString(7);
                     String dgr=rs.getString(8);
                     System.out.print("di="+d_id+";");
                     System.out.print("sn="+ssn+";");
                     System.out.print("floor="+dfl+";");
                     System.out.print("status="+dst+";");
                     System.out.print("lived_number="+dlive+";");
                     System.out.print("sdept="+dsp+";");
                     System.out.print("class="+dcl+";");
                     System.out.print("grade="+dgr+";");
                     System.out.println();


                 }
            rs.close();//数据库先开后关
            pst.close();
            conn.close();//关闭数据库
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }
}
